package com.itheima.consumer.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Objects;

@Slf4j
@Component
public class SpringRabbitListener {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.queue",durable = "true"),exchange = @Exchange(name="delay.direct",delayed = "true"),
            key = "delay"
    ))
    public void listenDelayMessage(String msg){
        log.info("接收到delay.queue的延迟消息:{}",msg);
    }

    @RabbitListener(queues = "dlx.queue")
    public void listenerDlxQueue(String msg){
        log.info("msg:{}",msg);
    }

    @RabbitListener(queues = "object.queue")
    public void objectListener1(Message msg){
        log.info("objectListener1-收到的消息是:{}",new String(msg.getBody()));
        log.info("消息id是:{}",msg.getMessageProperties().getMessageId());
    }




//交换机
    @RabbitListener(bindings ={
            @QueueBinding(
                    //队列
                    value = @Queue(value = "hmall.direct.queue1"),
                    //交换机
                    exchange = @Exchange(value = "hmall.direct.exchange1",type = ExchangeTypes.DIRECT),
                    //路由的key
                    key = {"java","php"}
            )
    } )
public void annotationListener(String msg){
        log.info("message:{}",msg);

    }

/**
 * 消息监听
 */
@RabbitListener(queues = "object.queue")
public void objectListener1(Map<String, Object> msg){
    log.info("objectListener1-收到的消息是:{}",msg);
}






    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "topic.queue1")
    public void topicQueueListener1(String msg){
        log.info("topicQueueListener1消费者接收到消息:{}",msg);
    }

    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "topic.queue2")
    public void topicQueueListener2(String msg){
        log.info("topicQueueListener2消费者接收到消息:{}",msg);
    }







    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "direct.queue1")
    public void directliQueueListener1(String msg){
        log.info("directliQueueListener1消费者接收到消息:{}",msg);
    }

    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "direct.queue2")
    public void directliQueueListener2(String msg){
        log.info("directliQueueListener2消费者接收到消息:{}",msg);
    }





    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "fanout.queue1")
    public void fanoutQueueListener1(String msg){
        log.info("fanoutQueueListener1消费者接收到消息:{}",msg);
    }

    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "fanout.queue2")
    public void fanoutQueueListener2(String msg){
        log.info("fanoutQueueListener2消费者接收到消息:{}",msg);
    }








    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "work.queue")
    public void workQueueListener1(String msg){
        log.info("workQueueListener1消费者接收到消息:{}",msg);
    }

    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "work.queue")
    public void workQueueListener2(String msg){
        log.info("workQueueListener2消费者接收到消息:{}",msg);
    }

    /**
     * 消息监听
     * @param msg
     */
    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueueMessage(String msg){
        log.info("spring消费者接收到消息:{}",msg);
    }

}
